package com.scoy.honeymei.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.scoy.honeymei.adapter.tabadapter.OyAdapter;
import com.scoy.honeymei.bean.ShopTicketBean;
import com.scoy.honeymei.databinding.ItemTicketCheckShopBinding;
import com.scoy.honeymei.utils.TimeUtil;

import org.jetbrains.annotations.NotNull;

public class ShopTicketCheckAdapter extends OyAdapter<ShopTicketBean> {


    public ShopTicketCheckAdapter(Context context) {
        super(context);
    }

    @NonNull
    @NotNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        ItemTicketCheckShopBinding binding = ItemTicketCheckShopBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
        return new OyHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull RecyclerView.ViewHolder holder, int position) {
        OyHolder mHolder = (OyHolder) holder;
        ShopTicketBean mBean = datalist.get(position);
        mHolder.binding.ictPriceTv.setText(mBean.getMoney());
        mHolder.binding.ictTitleTv.setText(mBean.getType_name());
        mHolder.binding.ictValuedateTv.setText(TimeUtil.getLongToDatePHP(mBean.getEndtime(), "yyyy-MM-dd"));
        mHolder.binding.ictFulluseTv.setText("满" + mBean.getCondition() + "元可用");
        mHolder.binding.ictBtnTv.setSelected(mBean.isCheck());

        mHolder.binding.ictBtnTv.setOnClickListener(view -> {
            if (onOneClick != null) {
                onOneClick.oneClick(position);
            }
        });


    }

    static class OyHolder extends RecyclerView.ViewHolder {
        private ItemTicketCheckShopBinding binding;

        public OyHolder(ItemTicketCheckShopBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }

}
